<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>分类添加</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <meta name="csrf-token" content="{{csrf_token()}}">
        @include('admin.public.style')
        @include('admin.public.script')
    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form" id="art_form">
                    <input type="hidden" name="_token" value="{{csrf_token()}}">
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>上级类名
                        </label>
                        <div class="layui-input-inline">
                            <select name="pid">
                                <option value="0">请选择上级类</option>
                                @foreach($cate as $v)
                                <option value="{{$v->id}}">{{$v->title}}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>文章标题
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="title" name="title" required="" style="width:400px" lay-verify="required"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label for="username" class="layui-form-label">缩略图</label>
                        <div class="layui-upload layui-input-block">
                            <input type="hidden" id="img1" class="hidden" name="art_thumb" value="">
                            <button type="button" class="layui-btn" id="test1"><i class="layui-icon">&#xe67c;</i>上传图片</button>
                            <input type="file" name="photo" id="photo_upload" style="display: none">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label for="username" class="layui-form-label"></label>
                        <div class="layui-input-block">
                            <img src="" alt="" id="art_thumb_img" style="width:100px">
                        </div>
                    </div>
                    <div class="layui-form-item  layui-form-text">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>内容
                        </label>
                        <div class="layui-input-block">
                            {{--加载编辑器的容器--}}
                            <script id="container" name="content" style="height: 500px" type="text/plain">
                                {{--@php--}}
                                    {{--echo htmlspecialchars_decode($article['content']);--}}
                                {{--@endphp--}}
                            </script>
                            {{--配置文件--}}
                            <script type="text/javascript" src="/ueditor/ueditor.config.js"></script>
                            {{--编辑器源码文件--}}
                            <script type="text/javascript" src="/ueditor/ueditor.all.js"></script>
                            {{--语言包--}}
                            <script type="text/javascript" src="/ueditor/lang/zh-cn/zh-cn.js"></script>
                            {{--实例化编辑器--}}
                            <script type="text/javascript">
                                var ue = UE.getEditor('container');
                                ue.ready(function(){
                                    ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');
                                });
                            </script>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_repass" class="layui-form-label"></label>
                        <button class="layui-btn" lay-filter="add" lay-submit="">增加</button>
                    </div>
                </form>
            </div>
        </div>
        <script>
            layui.use(['form', 'layer','jquery','upload', 'element'],
            function() {
                var $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer,
                upload = layui.upload,
                element = layui.element;

                $('#test1').on('click',function(){
                    $('#photo_upload').trigger('click');
                    $('#photo_upload').on('change',function(){
                        var obj = this;
                        var formData = new FormData($("#art_form")[0]);
                        $.ajax({
                            url:"upload",
                            type:"post",
                            data:formData,
                            processData:false,
                            contentType:false,
                            success:function(data){
                                if(data.ServerNo == 200){
                                    $("#art_thumb_img").attr('src','{{env('ALIOSS_DOMAIN')}}'+data['ResultData']);
                                    $('input[name=art_thumb]').val(data)
                                    $(obj).off('change')
                                }
                            }
                        })
                    })
                })
            });


        </script>
    </body>

</html>